﻿@page
@model FytSoa.Web.Pages.FytAdmin.Shop.BrandModifyModel
@{
    ViewData["Title"] = "品牌编辑";
    Layout = "~/Pages/FytAdmin/_Layout.cshtml";
}
<style>
    .help-block {
        color: #999;
        font-size: 12px;
        display: block;
        padding: 5px 0;
    }

    .form-cus {
        width: 70%;
        float: right;
    }

    .layui-form-item .layui-input-inline {
        width: 238px;
    }

    .cur-image {
        width: 24%;
        position: absolute;
        left: 25px;
        top: 0px;
        margin-bottom: 0px;
    }


        .cur-image .add-photo.default {
            height: 170px;
        }

        .cur-image .select-newimg {
            padding-top: 55px;
        }

        .cur-image .add-photo img {
            height: 170px;
        }

    .form-cus .layui-form-item.cell {
        display: table;
    }

        .form-cus .layui-form-item.cell .layui-inline {
            display: table-cell;
        }

    .widget-footer {
        border: 1px solid #f6f9fd !important;
        background-color: #f6f9fd;
        text-align: center;
        color: rgb(163, 175, 183);
    }

        .widget-footer span {
            display: block;
            line-height: 25px;
            color: #333;
        }
</style>
<div id="app">
    <form class="layui-form form-cus" action="" v-if="m">
        <div class="layui-form-item">
            <label class="layui-form-label">所属类别</label>
            <div class="layui-input-block">
                <select id="types" name="types" lay-verify="required" lay-search="">
                    <option value="0">所有</option>
                    <option :value="it.guid" v-for="it in list">{{it.columnTitle}}</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌名称</label>
            <div class="layui-input-block">
                <input type="text" v-model="m.brandName" name="brandName" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌别名</label>
            <div class="layui-input-block">
                <input type="text" v-model="m.nickName" name="nickName" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">网址</label>
            <div class="layui-input-block">
                <input type="text" v-model="m.siteUrl" name="siteUrl" maxlength="200" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <div id="sort" style="position:relative; top:16px;"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否推荐</label>
            <div class="layui-input-block">
                <input type="checkbox" id="istop" name="isTop" lay-skin="switch" lay-text="是|否">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌介绍</label>
            <div class="layui-input-block">
                <textarea name="summary" v-model="m.summary" class="layui-textarea" style="min-height:100px;"></textarea>
            </div>
        </div>
        <ul class="addpic-list cur-image clearfix">
            <li>
                <div class="add-photo default">
                    <input class="imgv" v-model="m.logo" name="logo" id="logo" type="hidden">
                    <div class="select-newimg fyt-cloud " :class="m.logo?'layui-hide':''" data-text="headPic" data-img="imgShow" data-type="form">
                        <i class="icon-addphote"></i>
                        <span>选择Logo</span>
                    </div>
                    <div class="add-photo-wall" :class="!m.logo?'layui-hide':''">
                        <img id="imgShow" :src="m.logo">
                        <div class="phote-edit">
                            <a class="photo-tool fyt-cloud" data-text="logo" data-img="imgShow" data-type="form" href="javascript:void(0)"><i class="layui-icon layui-icon-edit"></i>更换</a>
                            <a class="photo-tool last" href="javascript:void(0)" onclick="oc.deleteFile()"><i class="layui-icon layui-icon-delete"></i>删除</a>
                        </div>
                        <div class="cover">Logo</div>
                    </div>
                </div>
            </li>

        </ul>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="submit" id="submit"><i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-hide"></i>立即提交</button>
                <button type="button" class="layui-btn layui-btn-primary btn-open-close">取消</button>
            </div>
        </div>
    </form>
</div>
@section Scripts{
    <script>
        var oc, vm = new Vue({
            el: '#app',
            data: {
                m: {},
                list:[]
            }
        });
        layui.config({
            base: '/themes/js/modules/'
        }).use(['layer', 'jquery', 'common', 'form', 'slider'], function () {
            var form = layui.form, $ = layui.jquery, os = layui.common, slider = layui.slider;
            vm.m.guid = os.getUrlParam('guid');
            os.cloudFile();
            var sort=slider.render({
                elem: '#sort'
                , theme: '#1E9FFF'
                , input: true
                , change: function (value) {
                    vm.m.sort = value;
                }
            });
            var index = parent.layer.getFrameIndex(window.name);
            oc = {
                init() {
                    os.ajax('api/shop/brand/getmodel', { parm: vm.m.guid }, function (res) {
                        if (res.statusCode === 200) {
                            vm.m = res.data.model;
                            vm.list = res.data.list; //console.log(vm.list);
                            sort.setValue(vm.m.sort);
                            if (vm.m.isTop) {
                                $("#istop").prop("checked", true);
                            } else {
                                $("#istop").prop("checked", false);
                            }
                            vm.$nextTick(function () {
                                $("#types").val(vm.m.typeGuid);
                                form.render();
                            });
                        } else {
                            os.error(res.message);
                        }
                    });
                },
                fileSave(v) {
                    $(".select-newimg").addClass('layui-hide');
                    $(".add-photo-wall").removeClass('layui-hide');
                    $('#logo').val(v);
                    $('#imgShow').attr('src', v);
                    vm.m.logo = v;
                },
                deleteFile() {
                    $(".select-newimg").removeClass('layui-hide');
                    $(".add-photo-wall").addClass('layui-hide');
                    $('#logo').val('');
                    $('#imgShow').attr('src', '');
                    vm.m.logo = "";
                }

            };
            oc.init();
            //监听提交
            form.on('submit(submit)', function (data) {
                $('#submit').attr('disabled', true).find('i').removeClass('layui-hide');
                var urls = "api/shop/brand/add";
                if (vm.m.guid) {
                    urls = "api/shop/brand/update";
                }
                vm.m.isTop = data.field.isTop === 'on' ? true : false;
                vm.m.typeGuid = data.field.types;
                os.ajax(urls, vm.m, function (res) {
                    $('#submit').attr('disabled', false).find('i').addClass('layui-hide');
                    if (res.statusCode == 200) {
                        parent.layer.close(index);
                    }
                    else {
                        os.error(res.message);
                    }
                });
                return false;
            });
            $(".btn-open-close").on('click', function () {
                parent.layer.close(index);
            });
        });
    </script>
}
